1. Field of the Invention
Methods and apparatuses consistent with the present invention relate to managing stacks in a virtual machine. More particularly, the present invention relates to an apparatus and method for managing stacks in a virtual machine, which can reduce stack overhead by using memory directly connected with a processor when performing a push or pop on the stacks.
2. Description of the Related Art
Generally, a virtual machine provides a standard application performance environment that ensures mobility of an application. Here, a representative example of this virtual machine is Java Virtual Machine (JVM).
Java is an object-oriented programming language that can be used to produce platform-independent code. The Java code is compiled into Java byte code by a Java compiler, and the Java byte code is executed by the JVM.
FIG. 1A illustrates the structure of a conventional Java Virtual Machine (JVM).
As illustrated, a JVM includes a class loader 11, an execution engine 12, a method area 13, a heap 14, a Java stack 15, a personal computer (PC) register 16, and a native method stack 17.
The class loader 11 reads a Java class file from a network or a file system, puts the file at an appropriate position in memory depending on internal information included in the class file, and initializes the internal state.
The execution engine 12, which is a component for executing execution code of a class, recognizes and executes JVM machine commands, and while executed, converts JVM commands into machine code of a central processing unit (CPU) so as to improve the speed.
FIG. 1B illustrates the structure of a conventional Java class file.
As illustrated, Java classes are generally transmitted or stored in a class-file format, and the class-file format includes various class-related attributes. Here, the class-file format consists of a class header that indicates basic attributes, a constant pool that manages all constants, interfaces that include information about an interface of a class file, fields that include information about files, and methods, which are stored as byte-code.
FIG. 2A illustrates a basic unit for management of a Java stack by a conventional JVM.
StackStruct is used to manage a stack chuck, and includes the size of a stack and pointer information of the next stack.
FrameStruct is used to manage a frame generated whenever a function is called, and includes information on a method being executed, the pointer of the previous frame, the pointer of the previous stack, the previous program counter, a monitor object, and a stack chunk that belongs to a current frame.
FIG. 2B illustrates a conventional stack-management structure. Here, a process of managing stacks in a JVM 10 is described. The process of managing stacks occurs when performing a push and a pop.
First, in the case where a push is performed on stacks by calling a function in a class, it is checked whether a frame pointer can be added by checking the space of a stack chunk 23.
Then, if the space of the current stack chunk 23 is insufficient, it is checked whether there exists the next stack chunk. In the case where there exists no next stack chunk, a new stack chunk 22 is allocated from a heap area 21 in memory.
If a stack chuck 22 has been already allocated in the next chuck, the stack chunk 22 is specified as the current stack chuck.
Then, a frame pointer 24 is generated in the specified stack chunk 22, and the frame pointer 24 generated in the uppermost frame pointer is specified.
Then, the stack chunk of the current frame pointer 24 is specified as the stack chunk 22 of the allocated area.
Further, in the case where a pop is performed by calling a function, the current frame pointer 24 moves to the previous frame pointer, e.g., a frame pointer 25.
Then, the stack chunk of the current frame pointer 25 is specified as the stack chunk 23 that the current frame pointer 25 points to.
However, in the case where stacks are operated in the manner illustrated above, the stack area exists in a general memory area connected through an external bus.
As such, according to a conventional art, in order to handle data in memory, data in memory should be read to a register, but because data is read via an external bus, the transmission speed becomes low, which is a problem.
Korean Unexamined Patent 2004-111193 (Management of Stack-Based Memory Usage in a Processor) discloses a technology that determines whether a data subsystem is to operate as cache memory or as scratchpad memory in which line fetches from external memory are suppressed, and programs a control bit to cause the data subsystem to be operated as either a cache or scratchpad memory depending on the determination. However, this patent does not mention a technology that reads data from memory directly connected with a processor, which is not general memory connected to an external bus, when reading stacks.